#include "World.h"
#include "ColourHelper.h"


World::World(void)
{
}

World::~World(void)
{
}

void World::Init()
{
	// Set up  default camera
	Cameras.AddCamera(0, new Camera());

	// Set up default lights
	Lights.Init();

	// add default object manager to our world
	WorldObjects = new GameObjectManager();
	Add(WorldObjects);
}

void World::Update()
{
	// update all objects
	for(unsigned int i=0; i< WorldManagers.size(); i++)
		WorldManagers[i]->Update();
}

void World::Render()
{
	// set current view matrix
	SimpleRender::Get().g_pd3dDevice->SetTransform( D3DTS_VIEW, &Cameras.GetViewMatrix() );

	// render background
	RenderBackground();

	// render all objects
	for(unsigned int i=0; i< WorldManagers.size(); i++)
		WorldManagers[i]->Render();
}

// by default, render background as black
void World::RenderBackground()
{
	// clear the screen
	SimpleRender::Get().ClearScreen(Colour::BLACK);
}

void World::DestroyAllObjects()
{
	// delete all objectmanagers
	for(unsigned int i=0; i< WorldManagers.size(); i++)
		delete WorldManagers[i];
}

void World::Add( GameObjectManager* objectManager )
{
	WorldManagers.push_back(objectManager);
}

void World::Add( GameObject* worldObject )
{
	WorldObjects->Add(worldObject);
}


